package org.jeecg.modules.sssj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import org.jeecg.modules.sssj.entity.SssjFphz;
import org.jeecg.modules.sssj.mapper.SssjFphzMapper;
import org.jeecg.modules.sssj.service.ISssjFphzService;
import org.jeecg.modules.sssj.vo.FphzVo;
import org.jeecg.modules.sssj.vo.FpzlhzVo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @Description: 实时数据-发票汇总
 * @Author: jeecg-boot
 * @Date:   2022-06-13
 * @Version: V1.0
 */
@Service
public class SssjFphzServiceImpl extends MppServiceImpl<SssjFphzMapper, SssjFphz> implements ISssjFphzService {

    @Override
    public void insertJxxFphz(String tynsrsbh, Date kssj, Date jssj) {
        baseMapper.insertJxxFphz(tynsrsbh, kssj, jssj);
    }

    @Override
    public List<SssjFphz> selectJxxFphz(String tynsrsbh, Date kssj, Date jssj) {
        return baseMapper.selectJxxFphz(tynsrsbh, kssj, jssj);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void generateJxxFphz(String tynsrsbh, Date kssj, Date jssj) {
        //删除所属年月在起止时间范围内的企业
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        String ssnyKs = sdf.format(kssj);
        String ssnyJs = sdf.format(jssj);
        //先将状态改成已删除
        baseMapper.updateNsrJxxFphzToDelStatus(tynsrsbh, ssnyKs, ssnyJs);
        Calendar jssjCal = Calendar.getInstance();
        jssjCal.setTime(jssj);
        jssjCal.set(Calendar.HOUR, 23);
        jssjCal.set(Calendar.MINUTE, 59);
        jssjCal.set(Calendar.SECOND, 59);
        List<SssjFphz> sssjFphzs = baseMapper.selectJxxFphz(tynsrsbh, kssj, jssjCal.getTime());
        this.saveOrUpdateBatchByMultiId(sssjFphzs);
    }

    @Override
    public String getNsrMaxSsny(String tynsrsbh) {
        return baseMapper.getNsrMaxSsny(tynsrsbh);
    }

    @Override
    public FphzVo selectNsrFphz(String tynsrsbh, String ssny, String jxxlx) {
        return baseMapper.selectNsrFphz(tynsrsbh, ssny, jxxlx);
    }

    @Override
    public List<FpzlhzVo> selectNsrFpzlHz(String tynsrsbh, String ssny, String jxxlx) {
        return baseMapper.selectNsrFpzlHz(tynsrsbh, ssny, jxxlx);
    }
}
